import AutoImport from 'unplugin-auto-import/vite'
import {VueRouterAutoImports} from 'unplugin-vue-router'
import {DirResolverHelper, AutoGenerateImports, vue3Presets} from 'vite-auto-import-resolvers'
import {detectResolvers} from "../shared/detect";
import {ElementPlusResolver, TDesignResolver} from "unplugin-vue-components/resolvers";

// 自动导入常用的 Vue 生态库
// https://github.com/unplugin/unplugin-auto-import
export default function createAutoImport() {
    const autoImportDirs = ['src/store/**', 'src/components/**', 'src/api/**', 'src/utils/**', 'src/views/**',]
    return AutoImport({
        autoImportDirs,
        vueTemplate: true,
        imports: [
            ...AutoGenerateImports({
                include: [...vue3Presets],
                exclude: ['vue-router'],
            }),
            VueRouterAutoImports,
        ],
        resolvers: detectResolvers({
            onlyExist: [
                [ElementPlusResolver(), 'element-plus'],
                [TDesignResolver({library: 'vue-next'}), 'tdesign-vue-next'],
            ],
        }),
    })
}
